#include "TreeNode.h"
#include <climits>
bool isValidBST(TreeNode* root) {
    return isValidBSTHelper(root, INT_MIN, INT_MAX);
}

bool isValidBSTHelper(TreeNode* root, int min, int max) {
    if (root == nullptr) { // 空树是有效的BST
        return true;
    }
    if (root->val >= max || root->val <= min) {
        return false;
    }
    return isValidBSTHelper(root->left, min, root->val) && 
        isValidBSTHelper(root->right, root->val, max);
}